<template>
	<view class="page receive">
		<!-- 背景图 -->
		<view class="receive_nav">
			<image :src="info.img" mode="">
			</image>
		</view>
		<!-- 头部 -->
		<view class="receive_head">
			<view class="font-333333 font14 font-b">{{info.name}}</view>
			<!-- 10满减卷  -->
			<view class="receive_money" v-if="info.coupon_type==10">
				<text class="font-assist font11">￥</text>
				<text class="font-assist font22 font-b margin_num">{{info.reduce_money}}</text>
				<text class="font-666666 font11">满￥{{info.full_money}}使用</text>
			</view>
			<!-- 20折扣卷 -->
			<view class="receive_money" v-if="info.coupon_type==20">
				<text class="font-ff6428 font22 font-b margin_num">{{info.discount*10}}折</text>
				<text class="font-666666 font11">全场不包含运费</text>
			</view>
			<!-- 30立即卷 -->
			<view class="receive_money" v-if="info.coupon_type==30">
				<text class="font-ff6428 font11">￥</text>
				<text class="font-ff6428 font22 font-b margin_num">立减{{info.reduce_money}}</text>
			</view>
			<!-- 40兑换卷 -->
			<view class="receive_money" v-if="info.coupon_type==40">
				<text class="font-ff6428 font22 font-b margin_num">兑换商品(无门槛限制)</text>
			</view>
			<!-- 50停车券 -->
			<view class="receive_money" v-if="info.coupon_type==50">
				<text class="font-ff6428 font22 font-b margin_num">停车券(无门槛限制)</text>
			</view>
			<view class="receive_label flex-row-start">
				<view class="flex-row-center font-ff6428 font11">{{info.verify_mode ==10?'线上使用':'线下门店核销'}}</view>
				<view class="flex-row-center font-ff6428 font11">{{info.is_give ==1?'支持转赠':'不支持转赠'}}</view>
			</view>
			<view class="head_rec font-ffffff font15 flex-row-center" :class="info.couponObj.type?'':'grey'" @click="OncouponReceive">{{info.couponObj.title?info.couponObj.title:''}}
			</view>
		</view>
		<!-- 详情 -->
		<view class="receive_info">
			<view class="receivei_time">
				<view class="font-666666 font13 font-b">有效期</view>
				<view class="font-323232 font13">
					<view class="margin-20">开始时间:{{info.begin_title}}</view>
					<view class="margin-20">结束时间:{{info.end_title}}</view>
					<view class="margin-20">可用时段:{{info.week_title}}</view>
					<view class="margin-20">每日使用时段:{{info.everyday_title}}</view>
				</view>
			</view>
			<view class="receivei_box">
				<view class="font-666666 font13 font-b">使用规则</view>
				<view v-if="info.verify_mode ==10" class="flex-row-start margin-30" @click="Onpages">
					<view class="font-323232 font13">
						{{info.classify==10?'指定门店使用,点击查看详情':info.classify==20?'指定商品使用：点击查看指定商品':
					info.use_room_type==0?'指定房型使用：点击查看指定房型':info.use_room_type==1?'指定普通房型使用：点击查看指定房型':'指定时租房使用：点击查看指定时租房'}}</view>
					<image src="https://static.newbeaconhotels.com/app/hotel/group/more1.png" mode=""></image>
				</view>
				<view v-if="info.verify_mode ==20" class="flex-row-start margin-30">
					<view class="font-323232 font13">线下扫码核销</view>
				</view>
			</view>
			<view class="receivei_bos">
				<view class="font-666666 font13 font-b marginB-20">券详情</view>
				<rich-text class="font-323232 font13" :nodes="info.details"></rich-text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: null, //券ID
				info: {}, //券数据
				imgFullUrl: this.$Config.http_static, //图片地址
			}
		},
		onLoad(options) {
			let query = {}
			if (this.$Route.query.scene) {
				query = this.$base.OnWxoptions(this.$Route.query.scene)
			} else {
				query = options
			}
			this.id = query.id
			// 券详情
			this.OnDetails()
		},
		methods: {
			// 券详情
			OnDetails() {
				this.$Http({
					url: 'couponInfo',
					token: true,
					data: {
						id: this.id
					},
				}).then(res => {
					if (res.code == 1) {
						if (res.data.everyday_time == 1) {
							res.data.everyday_title = '全天可用'
						} else if (res.data.everyday_time == 2) {
							res.data.everyday_title = res.data.day_begin_time + '至' + res.data.day_end_time + '内'
						}
						res.data.img = this.imgFullUrl + res.data.img
						res.data.week = res.data.week.split(',');
						res.data.details = res.data.details.replace(/\<img/gi, '<img class="rich-img670"')
						res.data.couponObj = this.$base.Oncoupon(res.data.max_number, res.data.day_number, res.data
							.count, res.data.day_count)
						this.info = res.data
						this.Ontime()
					}
				});
			},
			//时间判断
			Ontime() {
				let week_title = []
				this.info.week.forEach(item => {
					item == 1 ? week_title.push('一') : ''
					item == 2 ? week_title.push('二') : ''
					item == 3 ? week_title.push('三') : ''
					item == 4 ? week_title.push('四') : ''
					item == 5 ? week_title.push('五') : ''
					item == 6 ? week_title.push('六') : ''
					item == 7 ? week_title.push('日') : ''
				})
				this.info.week_title = '周' + week_title.toString() + '可用'
				//固定时间
				if (this.info.use_type == 10) {
					this.info.begin_title = this.$base.formatTime(new Date(this.info.begin_time * 1000),
						"yyyy-MM-dd hh:mm:ss")
					this.info.end_title = this.$base.formatTime(new Date(this.info.end_time * 1000), "yyyy-MM-dd hh:mm:ss")
				} else if (this.info.use_type == 20) {
					//自定义时间
					// 领取后生效类型10-固定时间点生效,20-立即生效,30-一段时间后生效,40-第几天后生效
					let CC = ''
					if (this.info.after_collection == 30) {
						CC = this.info.after_time_type == 1 ? '分' : this.info.after_time_type == 2 ? '小时' : '天'
					}
					let begin = [{
							code: 10,
							title: this.$base.formatTime(new Date(this.info.after_begin_time * 1000),
								"yyyy-MM-dd hh:mm:ss")
						},
						{
							code: 20,
							title: '领取后立即生效'
						},
						{
							code: 30,
							title: '领取后' + this.info.after_number + CC + '后生效'
						},
						{
							code: 40,
							title: '领取后第' + this.info.after_the_day_number + '天' + this.info
								.after_the_day_begin_time +
								'后生效'
						},
					]

					// 生效后失效类型10-固定时间点失效,20-当日内有效,30-当周内有效,40-当月内有效,50-当年内有效,60-一段时间后失效,70-第几天后失效
					let HH = ''
					if (this.info.after_coming_into_force == 60) {
						HH = this.info.after_time_type_end == 1 ? '分' : this.info.after_time_type_end == 2 ? '小时' : '天'
					}
					let end = [{
							code: 10,
							title: '至' + this.$base.formatTime(new Date(this.info.after_end_time * 1000),
								"yyyy-MM-dd hh:mm:ss") + '期间使用'
						},
						{
							code: 20,
							title: '当日内有效'
						},
						{
							code: 30,
							title: '领取后本周内有效'
						},
						{
							code: 40,
							title: '领取后本月内有效'
						},
						{
							code: 50,
							title: '领取后本年内有效'
						},
						{
							code: 60,
							title: '领取后' + this.info.after_number_end.toString() + HH + '后失效'
						},
						{
							code: 70,
							title: '领取后第' + this.info.after_the_day_number_end + '天' + this.info
								.after_the_day_end_time +
								'后失效'
						},
					]
					begin.forEach(item => {
						if (item.code == this.info.after_collection) {
							this.info.begin_title = item.title
						}

					})
					end.forEach(item => {
						if (item.code == this.info.after_coming_into_force) {
							this.info.end_title = item.title
						}
					})
				}
			},
			//领券
			OncouponReceive() {
				var that = this
				if (that.info.couponObj.type) {
					this.$Http({
						url: 'couponReceive',
						token: true,
						type: 'POST',
						data: {
							coupon_id: this.id
						},
					}).then(res => {
						if (res.code == 1) {
							// 关闭当前页面
							uni.showModal({
								title: '操作提示',
								content: '恭喜您,领取成功~',
								confirmText: '我知道了',
								confirmColor: '#ff3c37',
								showCancel: false,
								success(res) {
									if (res.confirm) {
										that.$Router.replaceAll('/pages/coupon/list')
									}
								}
							})
						} else {
							uni.showToast({
								icon: 'none',
								duration: 2000,
								title: res.msg
							});
						}
					});
				} else {
					uni.showToast({
						icon: 'none',
						duration: 2000,
						title: that.info.couponObj.msg
					});
				}

			},
			//页面跳转
			Onpages() {
				//制定商品使用
				if (this.info.classify == 20) {
					this.$Router.push('/pages/group/list?id=' + this.info.id)
				}
				//酒店使用
				if (this.info.classify == 10 || this.info.classify == 30) {
					//指定普通房型使用
					if (this.info.use_room_type == 1) {
						this.$Router.push('/pages/hotel/hotelList?couponId=' + this.info.id)
					}
					//指定时租房使用
					if (this.info.use_room_type == 2) {
						this.$Router.push('/pages/hotel/hourRoomList?couponId=' + this.info.id)
					}
				}
			}
		}
	}
</script>

<style lang="less">
	@import url("style.less");
</style>
